namespace BM.Tools.WebControls.MForm.Controls
{    
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Web.UI;

    using BM.Tools.WebControls.MForm.Controls.Items;
    using BM.Tools.WebControls.MForm.Controls.Modifiers;
    using BM.Tools.WebControls.MForm.Design;

    /// <summary>
    /// The <see cref="Offspring" /> object that represents all those xml chunks that may have children
    /// </summary>
    [Designer(typeof(OffspringsOwnerDesigner))]
    public abstract class OffspringsOwner : Offspring
    {
        private bool isInitComplete = false;
        private ITemplate contents;

        /// <summary>
        /// Initializes a new instance of the <see cref="OffspringsOwner"/> class.
        /// </summary>
        protected OffspringsOwner()
        {
            Modifiers = new ModifiersCollection<OffspringsOwnerModifier, OffspringsOwner, OffspringsOwnerItem>(this);
        }

        /// <summary>
        /// Gets or sets Contents.
        /// </summary>
        /// <value>
        /// The contents.
        /// </value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [Browsable(false)]
        [TemplateContainer(typeof(OffspringsOwnerItem))]
        [DefaultValue((string)null)]
        public ITemplate Contents
        {
            get
            {
                return contents;
            }

            set
            {
                contents = value;
                if (isInitComplete) 
                {                    
                    CreateChildControls();
                }                
            }
        }

        /// <summary>
        /// Gets Modifiers.
        /// </summary>
        /// <value>
        /// The modifiers.
        /// </value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [NotifyParentProperty(true)]
        public Collection<OffspringsOwnerModifier> Modifiers
        {
            get;
            private set;            
        }

        /// <summary>
        /// Performs on init.
        /// </summary>
        /// <param name="e">
        /// The event args.
        /// </param>
        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);
            isInitComplete = true;
        }
    }
}